package com.example.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.utils.CurrentUserUtil;
import com.example.dao.SensitiveTypeDao;
import com.example.entity.domain.Hierarchy;
import com.example.entity.domain.SensitiveType;
import com.example.entity.dto.BaseDTO;
import com.example.entity.vo.SensitiveTypeVo;
import com.example.service.SensitiveTypeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: zhuxiaokang
 * @CreateTime: 2025-05-07
 * @Description: 敏感类型
 * @Version: 1.0
 */

@Service
public class SensitiveTypeServiceImpl implements SensitiveTypeService {

    @Resource
    private SensitiveTypeDao sensitiveTypeDao;

    @Override
    public Page<SensitiveType> list(BaseDTO baseDTO) {
        Page<SensitiveType> page = new Page<>(baseDTO.getPageNum(), baseDTO.getPageSize());
        return sensitiveTypeDao.pageList(page, baseDTO);
    }

    @Override
    public Boolean add(SensitiveType sensitiveType) {
        String username = CurrentUserUtil.getCurrentUsername();
        sensitiveType.setCreatedBy(username);
        sensitiveType.setCreatedTime(LocalDateTime.now());
        sensitiveType.setUpdatedBy(username);
        sensitiveType.setUpdatedTime(LocalDateTime.now());
        return sensitiveTypeDao.insert(sensitiveType) > 0;
    }

    @Override
    public Boolean update(SensitiveType sensitiveType) {
        String username = CurrentUserUtil.getCurrentUsername();
        sensitiveType.setUpdatedBy(username);
        sensitiveType.setUpdatedTime(LocalDateTime.now());
        return sensitiveTypeDao.updateById(sensitiveType) > 0;
    }

    @Override
    public Boolean delete(Integer id) {
        return sensitiveTypeDao.deleteById(id) > 0;
    }

    @Override
    public List<SensitiveTypeVo> getSensitiveTypeList() {
        return sensitiveTypeDao.getSensitiveTypeList();
    }
}
